package com.itkaien.javaeebased.multipleSystem;

import java.util.concurrent.locks.Lock;

public class Work3 implements Runnable{


    private Integer ticker =100;

    private Lock lock;

    public Work3(Integer ticker, Lock lock) {
        this.ticker = ticker;
        this.lock = lock;
    }

    public Work3() {
    }

    @Override
    public void run() {

        while (ticker>10){
            try {
                lock.lock();
                if (ticker>10){
                    ticker--;
                }else {

                    System.out.println(Thread.currentThread().getName()+":ticker剩余:"+ticker);
                    break;
                }

                System.out.println(Thread.currentThread().getName()+":ticker剩余:"+ticker);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                lock.unlock();
            }

        }



    }
}
